#ifndef NETWORK_H
#define NETWORK_H
#include <linux/socket.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <linux/udp.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/proc_fs.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#include <linux/skbuff.h>
#include <linux/in.h>

#define MAX_BITS_MASK 32				// size in bits of ip mask
#define PORT_WILDCARD 0					// wildcard for ports
#define LOCALHOST  in_aton("127.0.0.1")	// localhost ip
#define IP_VERSION 4					// ip version used

// raw packet from netfilter
typedef struct {
	unsigned int   source_ip;      
	unsigned int   dest_ip;      
	unsigned short source_port;    
	unsigned short dest_port;   
	unsigned short protocol; 
	unsigned short version;
	char*  data;    
	int data_length;  
} rawPacket_t;

// attack types
typedef enum{
	ATTACK_NONE = 0,
	ATTACK_XMAS,
} attack_t;

// parameter from tcp header
// serves to store all tcp flags and the conversation side
typedef struct{	
	__u8 syn:1;
	__u8 ack:1;
	__u8 fin:1;
	__u8 rst:1;	
	__u8 psh:1;
	__u8 urg:1;
	__u8 ece:1;
	__u8 cwr:1;
	__u8 side;		
} tcpHeaderParams_t;
/*
 * function makeRawPacket
 * extract a packet from sk_buff
 * params: sk_buff - sk buffer from netfilter, packet - the packet to fill
 * 		   params - for tcp protocol we fill a special struct with bit flags
 */ 
 
static void makeRawPacket(struct sk_buff *skb, rawPacket_t *packet, tcpHeaderParams_t *params);
/*
 * function unserAttack
 * inspects the packet and the possible params and returns the correct attack type
 * params: in param - packet: the inspected packet, params: special params for the protocol
 */ 
static attack_t underAttack(rawPacket_t* packet, char *params);

/*
 * function applyMaskToIP
 * applies a given mask to a given ip after ntohl, meaning ip is in little endian variant endian
 * params		:  ip, mask (0-32)
 * return value	:  ip after mask is applied
 * assumptions  :  ip is in little endian format (not network format) and mask is between 0-32
 */
static __u32 applyMaskToIP(__u32 ip, __u8 mask);
#endif
